<?php
/**
 * @Author: Tekin
 * @Date:   2023-08-27 12:07:38
 * @Last Modified 2023-08-27
 */

if (!function_exists('dd')) {
    function dd($data)
    {
        echo "<pre>" . print_r($data, true) . "</pre>";
        exit;
    }
}
if (!function_exists('vd')) {
    function vd($arr)
    {
        echo "<pre>";
        var_dump($arr);
        echo "</pre>";
        die;
    }
}


/**
 * Maps a function to all non-iterable elements of an array or an object.
 *
 * This is similar to `array_walk_recursive()` but acts upon objects too.
 *
 * @param mixed    $value    The array, object, or scalar.
 * @param callable $callback The function to map onto $value.
 * @return mixed The value with the callback applied to all non-arrays and non-objects inside it.
 */
function map_deep($value, $callback) {
    if (is_array($value)) {
        foreach ($value as $index => $item) {
            $value[$index] = map_deep($item, $callback);
        }
    } elseif (is_object($value)) {
        $object_vars = get_object_vars($value);
        foreach ($object_vars as $property_name => $property_value) {
            $value->$property_name = map_deep($property_value, $callback);
        }
    } else {
        $value = call_user_func($callback, $value);
    }
    return $value;
}
/**
 * Normalizes EOL characters and strips duplicate whitespace.
 * @param string $str The string to normalize.
 * @return string The normalized string.
 */
function normalize_whitespace($str) {
    $str = trim($str);
    $str = str_replace("\r", "\n", $str);
    $str = preg_replace(array('/\n+/', '/[ \t]+/'), array("\n", ' '), $str);
    return $str;
}
if (!function_exists('str_contains')) {
    /**
     * Polyfill for `str_contains()` function added in PHP 8.0.
     *
     * Performs a case-sensitive check indicating if needle is
     * contained in haystack.
     *
     * @since 5.9.0
     *
     * @param string $haystack The string to search in.
     * @param string $needle   The substring to search for in the `$haystack`.
     * @return bool True if `$needle` is in `$haystack`, otherwise false.
     */
    function str_contains($haystack, $needle)
    {
        if ('' === $needle) {
            return true;
        }
        return false !== strpos($haystack, $needle);
    }
}
if (!function_exists('str_starts_with')) {
    /**
     * Polyfill for `str_starts_with()` function added in PHP 8.0.
     *
     * Performs a case-sensitive check indicating if
     * the haystack begins with needle.
     *
     * @since 5.9.0
     *
     * @param string $haystack The string to search in.
     * @param string $needle   The substring to search for in the `$haystack`.
     * @return bool True if `$haystack` starts with `$needle`, otherwise false.
     */
    function str_starts_with($haystack, $needle)
    {
        if ('' === $needle) {
            return true;
        }
        return 0 === strpos($haystack, $needle);
    }
}
if (!function_exists('str_ends_with')) {
    /**
     * Polyfill for `str_ends_with()` function added in PHP 8.0.
     *
     * Performs a case-sensitive check indicating if
     * the haystack ends with needle.
     *
     * @since 5.9.0
     *
     * @param string $haystack The string to search in.
     * @param string $needle   The substring to search for in the `$haystack`.
     * @return bool True if `$haystack` ends with `$needle`, otherwise false.
     */
    function str_ends_with($haystack, $needle)
    {
        if ('' === $haystack) {
            return '' === $needle;
        }
        $len = strlen($needle);
        return substr($haystack, -$len, $len) === $needle;
    }
}
/**
 * Checks for invalid UTF8 in a string.
 * @param string $text   The text which is to be checked.
 * @param bool   $strip  Optional. Whether to attempt to strip out invalid UTF8. Default false.
 * @return string The checked text.
 */
function check_invalid_utf8($text, $strip = false) {
    $text = (string) $text;
    if (0 === strlen($text)) {
        return '';
    }
    // Check for support for utf8 in the installed PCRE library once and store the result in a static.
    static $utf8_pcre = null;
    if (!isset($utf8_pcre)) {
        // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
        $utf8_pcre = @preg_match('/^./u', 'a');
    }
    // We can't demand utf8 in the PCRE installation, so just return the string in those cases.
    if (!$utf8_pcre) {
        return $text;
    }
    // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- preg_match fails when it encounters invalid UTF8 in $text.
    if (1 === @preg_match('/^./us', $text)) {
        return $text;
    }
    // Attempt to strip the bad chars if requested (not recommended).
    if ($strip && function_exists('iconv')) {
        return iconv('utf-8', 'utf-8', $text);
    }
    return '';
}
function pre_kses_less_than_callback($matches) {
    if (!str_contains($matches[0], '>')) {
        return htmlentities($matches[0]);
    }
    return $matches[0];
}
/**
 * Properly strips all HTML tags including script and style
 *
 * This differs from strip_tags() because it removes the contents of
 * the `<script>` and `<style>` tags. E.g. `strip_tags( '<script>something</script>' )`
 * will return 'something'. wp_strip_all_tags will return ''
 *
 * @since 2.9.0
 *
 * @param string $text          String containing HTML tags
 * @param bool   $remove_breaks Optional. Whether to remove left over line breaks and white space chars
 * @return string The processed string.
 */
function strip_all_tags($text, $remove_breaks = false) {
    if (is_null($text)) {
        return '';
    }
    if (!is_scalar($text)) {
        /*
             * To maintain consistency with pre-PHP 8 error levels,
             * trigger_error() is used to trigger an E_USER_WARNING,
             * rather than _doing_it_wrong(), which triggers an E_USER_NOTICE.
        */
        trigger_error(
            sprintf(
                /* translators: 1: The function name, 2: The argument number, 3: The argument name, 4: The expected type, 5: The provided type. */
                __('Warning: %1$s expects parameter %2$s (%3$s) to be a %4$s, %5$s given.'),
                __FUNCTION__,
                '#1',
                '$text',
                'string',
                gettype($text)
            ),
            E_USER_WARNING
        );
        return '';
    }
    $text = preg_replace('@<(script|style)[^>]*?>.*?</\\1>@si', '', $text);
    $text = strip_tags($text);
    if ($remove_breaks) {
        $text = preg_replace('/[\r\n\t ]+/', ' ', $text);
    }
    return trim($text);
}
/**
 * Internal helper function to sanitize a string from user input or from the database.
 *
 * @param string $str           String to sanitize.
 * @param bool   $keep_newlines Optional. Whether to keep newlines. Default: false.
 * @return string Sanitized string.
 */
function sanitize_text_fields($str, $keep_newlines = false) {
    if (is_object($str) || is_array($str)) {
        return '';
    }
    $str = (string) $str;
    $filtered = check_invalid_utf8($str);
    if (false !== strpos($filtered, '<')) {
        $filtered = preg_replace_callback('%<[^>]*?((?=<)|>|$)%', 'pre_kses_less_than_callback', $filtered);
        // This will strip extra whitespace for us.
        $filtered = strip_all_tags($filtered, false);
        /*
             * Use HTML entities in a special case to make sure that
             * later newline stripping stages cannot lead to a functional tag.
        */
        $filtered = str_replace("<\n", "&lt;\n", $filtered);
    }
    if (!$keep_newlines) {
        $filtered = preg_replace('/[\r\n\t ]+/', ' ', $filtered);
    }
    $filtered = trim($filtered);
    // Remove percent-encoded characters.
    $found = false;
    while (preg_match('/%[a-f0-9]{2}/i', $filtered, $match)) {
        $filtered = str_replace($match[0], '', $filtered);
        $found = true;
    }
    if ($found) {
        // Strip out the whitespace that may now exist after removing percent-encoded characters.
        $filtered = trim(preg_replace('/ +/', ' ', $filtered));
    }
    return $filtered;
}
$t = $_REQUEST['t'];
$a = $_REQUEST['a'];
echo sanitize_text_fields($t);
echo sanitize_text_fields($a);

